#include<iostream>
#include "../tools/cpp-httplib-master/httplib.h"

void hi(const httplib::Request& req,httplib::Response& res)
{
    res.version = "http2";
    res.status = 200;
    res.body = "hello world\n";
    res.set_content("Hello World!", "text/plain");
}
void numbers(const httplib::Request& req,httplib::Response& res)
{
    auto header = req.headers;
    std::cout<<header<<std::endl;
    auto number = req.matches[1];
    res.set_content(number,"text/plain");
}
void upload(const httplib::Request& req,httplib::Response& res)
{
    size_t sz = req.files.size();
    bool ret = req.has_file("file");
    if(ret == false)
    {
        std::cout<<"不存在这个文件\n";
        return;
    }
    auto file = req.get_file_value("file");
    std::cout<<"filesize : "<<sz<<std::endl;
    std::cout<<"filename : "<<file.filename<<std::endl;
    std::cout<<"content : "<<file.content<<std::endl;
    std::cout<<"content_type : "<<file.content_type<<std::endl;
}
int main()
{
    httplib::Server svr;
    svr.Get("/hi",hi);
    svr.Get(R"(/numbers/(\d+))",numbers);
    svr.Post("/upload",upload);
    svr.listen("0.0.0.0",8888);
    return 0;
}



